package com.wxapp.admin.service.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxapp.admin.api.pojo.vm.user.PUserDetailVm;
import com.wxapp.admin.api.pojo.vm.user.PUserPageVm;
import com.wxapp.admin.api.pojo.vo.user.QUserPageVo;
import com.wxapp.admin.api.pojo.vo.user.*;
import com.wxapp.admin.service.service.UserService;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.common.util.check.CheckUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author lgl
 * @Description 用户
 * @Datetime 2022/4/28 16:22
 * @Modified By
 */
@RequestMapping("user")
@Tag(name = "用户管理")
@RestController
@RequiredArgsConstructor
public class UserController extends IBaseController {
    private final UserService userService;

    @PostMapping("/save")
    @Operation(summary ="保存用户信息")
    public ResultVm<String> saveUser(@Schema(hidden = true) @User UserVo userVo, @RequestBody QSaveVo qSaveVo) {
        return userService.saveUser(userVo, qSaveVo);
    }
    @PutMapping("/update")
    @Operation(summary ="更新用户信息")
    public ResultVm<String> updateUser(@Schema(hidden = true) @User UserVo userVo, @RequestBody QUserUpdateVo qSaveVo) {
        return userService.updateUser(userVo, qSaveVo);
    }
    @GetMapping("/detail")
    @Operation(summary ="得到用户详情")
    public ResultVm<PUserDetailVm> detailUser(@Schema(hidden = true) @User UserVo userVo, @RequestParam(value = "id", required = false) String id) {
        if (CheckUtil.isNotNullObject(id)) {
            userVo.setId(id);
        }
        return userService.detailUser(userVo);
    }
    @PostMapping("/page")
    @Operation(summary ="获取用户分页")
    public ResultVm<Page<PUserPageVm>> pageUser(@RequestBody QUserPageVo qSaveVo) {
        return userService.pageUser(qSaveVo);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary ="删除用户")
    public ResultVm<String> deleteUser(@PathVariable String id) {
        return userService.deleteUser(id);
    }

    @PutMapping("/updatePw")
    @Operation(summary ="更新密码")
    public ResultVm<String> updatePw(@Schema(hidden = true) @User UserVo userVo, @RequestBody QUpdatePwVo QUpdatePwVo) {
        return userService.updatePw(userVo, QUpdatePwVo);
    }
    @PutMapping("/updateAvatar")
    @Operation(summary ="更新头像")
    public ResultVm<String> updateAvatar(@RequestBody QUpdateAvatarVo qSaveVo, @Schema(hidden = true) @User UserVo userVo) {
        return userService.updateAvatar(userVo, qSaveVo);
    }
    @GetMapping("/test")
    @Operation(summary ="test")
    public String test() {
        return "hello word";
    }
}
